Skip to main content

classicube_sys\vectors\ivec/
mod.rs

1mod ops;
2
3use crate::{
4    Int32_MaxValue, Vec3_IsZero, Vec3_Set,
5    bindings::{IVec3, Vec3},
6    std_types::c_int,
7};
8
9impl IVec3 {
10    #[must_use]
11    pub const fn new(x: c_int, y: c_int, z: c_int) -> Self {
12        Self { x, y, z }
13    }
14
15    #[must_use]
16    pub const fn zero() -> Self {
17        Self { x: 0, y: 0, z: 0 }
18    }
19
20    pub fn set(&mut self, x: c_int, y: c_int, z: c_int) {
21        Vec3_Set!(self, x, y, z);
22    }
23
24    #[must_use]
25    pub fn is_zero(&self) -> bool {
26        Vec3_IsZero!(self)
27    }
28
29    #[must_use]
30    pub const fn max_value() -> Self {
31        IVec3_MaxValue()
32    }
33
34    #[must_use]
35    pub fn to_vec3(&self) -> Vec3 {
36        let mut result = Vec3::zero();
37        IVec3_ToVec3(&mut result, self);
38        result
39    }
40
41    #[must_use]
42    pub fn min(&self, b: IVec3) -> Self {
43        let mut result = Self::zero();
44        IVec3_Min(&mut result, self, &b);
45        result
46    }
47
48    #[must_use]
49    pub fn max(&self, b: IVec3) -> Self {
50        let mut result = Self::zero();
51        IVec3_Max(&mut result, self, &b);
52        result
53    }
54}
55
56impl From<IVec3> for Vec3 {
57    fn from(other: IVec3) -> Self {
58        other.to_vec3()
59    }
60}
61
62/// Returns a vector with all components set to `Int32_MaxValue`.
63#[must_use]
64pub const fn IVec3_MaxValue() -> IVec3 {
65    IVec3 {
66        x: Int32_MaxValue,
67        y: Int32_MaxValue,
68        z: Int32_MaxValue,
69    }
70}
71
72#[expect(
73    clippy::cast_precision_loss,
74    reason = "i32 to f32 precision loss is acceptable for world coordinates"
75)]
76pub fn IVec3_ToVec3(result: &mut Vec3, a: &IVec3) {
77    result.x = a.x as _;
78    result.y = a.y as _;
79    result.z = a.z as _;
80}
81
82pub fn IVec3_Min(result: &mut IVec3, a: &IVec3, b: &IVec3) {
83    result.x = a.x.min(b.x);
84    result.y = a.y.min(b.y);
85    result.z = a.z.min(b.z);
86}
87
88pub fn IVec3_Max(result: &mut IVec3, a: &IVec3, b: &IVec3) {
89    result.x = a.x.max(b.x);
90    result.y = a.y.max(b.y);
91    result.z = a.z.max(b.z);
92}